﻿using System.Collections.Generic;

namespace Framework.FluentTextStringBuilder.ExtensionCsv
{
    public static class CsvFtsbExtensions
    {
        /// <summary>
        /// Write a CSV line.
        /// </summary>
        /// <param name="builder">The builder.</param>
        /// <param name="navigationItems">The navigation items.</param>
        /// <returns></returns>
        public static ITextStringBuilderWriterFluent Csv(this ITextStringBuilderWriterFluent builder, IEnumerable<EnumerableExtension.NavigationItem<string>> navigationItems)
        {
            foreach (var navigationItem in navigationItems)
            {
                builder.Csv(navigationItem.Value, navigationItem);
            }

            return builder;
        }

        /// <summary>
        /// Write a CSV item.
        /// </summary>
        /// <param name="builder">The builder.</param>
        /// <param name="value">The value.</param>
        /// <param name="navigationItem">The navigation item.</param>
        /// <returns></returns>
        public static ITextStringBuilderWriterFluent Csv(this ITextStringBuilderWriterFluent builder, string value, EnumerableExtension.NavigationItem<string> navigationItem)
        {
            builder
                .Add(value);
            if (!navigationItem.IsLast)
            {
                builder.Add(",");
            }

            return builder;
        }
    }
}